package com.VitalFit.model.enums;

import lombok.Getter;

@Getter
public enum ResultEnum {

    REGISTER_SUCCESS(200, "注册成功"),
    REGISTER_FAILURE(500, "注册失败"),
    LOGIN_SUCCESS(200, "登陆成功"),
    LOGIN_FAILURE(500, "登陆失败"),
    PURCHASE_SUCCESS(200, "购买训练计划成功"),
    PURCHASE_FAILURE(500, "购买训练计划失败"),
    ORDER_SUCCESS(200, "预约训练成功"),
    ORDER_FAILURE(500, "预约训练失败"),
    NOT_FOUND(404, "未找到资源"),
    UNAUTHORIZED(401, "未授权");


    private final int code;
    private final String message;

    ResultEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 提供静态方法根据code获取对应的ResultEnum实例
    public static ResultEnum getByCode(int code) {
        for (ResultEnum resultEnum : ResultEnum.values()) {
            if (resultEnum.getCode() == code) {
                return resultEnum;
            }
        }
        throw new IllegalArgumentException("No matching constant for code " + code);
    }
}